<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		// helper
		$this->load->helper('url');
		
		//$this->load->view('pc/header');
		$this->load->library('user_agent');
		
		if ($this->agent->is_mobile("iphone") || $this->agent->is_mobile())
		{
		    $agent = $this->agent->mobile();
			
			redirect("http://www.intern55.com/iphone", "refresh");
		}
		else{
			$this->load->view('pc/main');
		}
	}
	
	public function otoiawase(){
		$this->load->helper(array('form', 'url'));
		$this->load->view('pc/otoiawase', array(
		));
	}

	public function receive_form(){
		$this->load->helper(array('form', 'url'));

		$this->load->library('form_validation');
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
		
		$this->form_validation->set_rules('name', 'お名前', 'required');
		$this->form_validation->set_rules('furigana', 'フリガナ', 'required');
		$this->form_validation->set_rules('mail', 'メール', 'required|valid_email');
		$this->form_validation->set_rules('place', '会社名または大学名', 'required');
		$this->form_validation->set_rules('phone', '電話番号', 'required');
		$this->form_validation->set_rules('address', '', '');
		$this->form_validation->set_rules('content', '', '');
		$this->form_validation->set_rules('url', '', '');

		// $info push to kakunin page
		$info["お名前"] = $_POST["name"];
		
		$info["フリガナ"] = $_POST["furigana"];
		
		$info["メールアドレス(PC)"] = $_POST["mail"];
		
		$info["電話番号"] = $_POST["phone"];
		
		$info["会社名または大学名"] = $_POST["place"];
		
		$info["住所"] = $_POST["address"];
		
		$info["URL"] = $_POST["url"];
		
		$info["内容"] = $_POST["content"];
		
		if ($this->form_validation->run() == FALSE)
		{
			$this->load->view('pc/otoiawase', array(
			));
		}
		else
		{
			//$this->load->view('formsuccess');
			
			$this->load->view('pc/form_kakunin', array(
				"info" => $info,
				"post" => $_POST,
			));
			
			//echo $this->email->print_debugger();
		}
	}

	public function send_form(){
		// $info push to check page
		$info["お名前"] = $_POST["name"];
		
		$info["フリガナ"] = $_POST["furigana"];
		
		$info["メールアドレス(PC)"] = $_POST["mail"];
		
		$info["電話番号"] = $_POST["phone"];
		
		$info["会社名または大学名"] = $_POST["place"];
		
		$info["住所"] = $_POST["address"];
		
		$info["内容"] = $_POST["content"];
		
		$mailcontent = "";
		foreach ($info as $key => $value) {
			$mailcontent .= "$key: $value\n";
		}
		//echo nl2br($mailcontent);
		
		$this->load->library('email');
		
		$this->email->from('your@example.com', 'Intern55');
		$this->email->to('nishimura@berryinc.jp'); 
		$this->email->cc('another@another-example.com');
		$this->email->bcc('them@their-example.com');
		
		$this->email->subject( "インターンシップお問い合わせ" );
		$this->email->message($mailcontent);
		
		//echo $this->email->print_debugger();
		if ( $this->email->send() )
			$this->load->view('pc/thanks', array(
			));
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */